import folium
from folium import plugins
import seaborn as sns
import numpy as np
import pandas as pd
import geopandas as gpd
import pyproj
from shapely import geometry
import matplotlib.pyplot as plt
%matplotlib inline
Perigrines = pd.read_csv(r'C:\Users\emack\Documents\UAF-Temperature\data\pfunique2.csv') # save to a dataframe
Perigrines.head() # This shows the first 5 entries of the DF.
From the metadata we have that the geophysics data is referenced to latlong (NAD27) datum. Let's use pyproj to transform it to both latlong (WGS84) and UTM zone 16 (WGS84).
# North American Datum 1927
p1 = pyproj.Proj(proj='latlong', datum='NAD27')
# WGS84 Latlong
p2 = pyproj.Proj(proj='latlong', datum='WGS84')
# WGS84 UTM Zone 16
p3 = pyproj.Proj(proj='utm', zone=16, datum='WGS84')
Perigrines['long_wgs84'], Perigrines['lat_wgs84'] = pyproj.transform(p1, p2,
Perigrines.longitude.values,
Perigrines.latitude.values)
Perigrines['E_utm'], Perigrines['N_utm'] = pyproj.transform(p1, p3,
Perigrines.longitude.values,
Perigrines.latitude.values)
Perigrines['geometry'] = [geometry.Point(x, y) for x, y in zip(Perigrines['long_wgs84'], Perigrines['lat_wgs84'])]
Perigrines = gpd.GeoDataFrame(Perigrines, geometry='geometry', crs="+init=epsg:4326")
Perigrines.to_csv(r'C:\Users\emack\Documents\UAF-Temperature\data\mag.csv')
Perigrines.head(3)
multipoints = geometry.MultiPoint(Perigrines['geometry'])
bounds = multipoints.envelope
gpd.GeoSeries(bounds).to_file(r'C:\Users\emack\Documents\UAF-Temperature\data\area_of_study_bounds.gpkg', 'GPKG')
coords = np.vstack(bounds.boundary.coords.xy)
Africa = (8.7832, 34.5085)
UAF_coords = (64.8558, -147.8335)
map_center = list(coords.mean(1))[::-1] # use a slice to get all the rows from the last column
Africa
m = folium.Map(location=Africa, zoom_start=3, control_scale=True)
folium.PolyLine(coords[::-1].T).add_to(m)
folium.LatLngPopup().add_to(m)
m
The 'long_wgs84 and lat_wgs84' columns confirm we have the correct CRS as they are the same as initial read from the .csv. The 'geometry' column is what we will use for later bounding-box zooming. the E_utm and N_utm are described here: https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system
Perigrines.head(50)
Perigrines.dropna(how='any', inplace=True)
pd.isna(Perigrines)
# convert to (n, 2) nd-array format for heatmap
stationArr = Perigrines[['latitude', 'longitude']].as_matrix()
# plot heatmap
m.add_children(plugins.HeatMap(stationArr, radius=15))
m
# mark each station as a point
for index, row in Perigrines.iterrows():
folium.CircleMarker([row['latitude'], row['longitude']],
radius=15,
#popup=row['name'],
fill_color="#3db7e4", # divvy color
).add_to(m)
# convert to (n, 2) nd-array format for heatmap
stationArr = Perigrines[['latitude', 'longitude']].as_matrix()
# plot heatmap
m.add_children(plugins.HeatMap(stationArr, radius=8))
m